package com.yanqu.road.dao.impl.channelcenter.washe;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.washe.config.WasheSkillConfig;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WasheSkillConfigDaoImpl extends TempDao {

    private static String getWasheSkillConfigSql = "select * from `t_n_washepvp_skill` where `activityId`=?";

    public Map<Integer, WasheSkillConfig> getWasheSkillConfigMap(int activityId) {
        Map<Integer, WasheSkillConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            call = getDb().getConnection().prepareCall(getWasheSkillConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                WasheSkillConfig config = new WasheSkillConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setSkillId(rs.getInt("skillId"));
                config.setPrice(rs.getString("price"));
                config.setSkillParam(rs.getString("skillParam"));
                config.setSkillName(rs.getString("skillName"));
                config.setSkillDesc(rs.getString("skillDesc"));
                config.setItemId(rs.getInt("itemId"));
                config.setMaxTime(rs.getInt("maxTime") * DateHelper.SECOND_MILLIONS);
                config.setOpen(rs.getInt("open"));

                // init
                config.init();

                map.put(config.getSkillId(), config);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
